package com.kingyun.gpsinspection.purificationservice.services.som.taskjobservice;

import com.cqhilink.api.common.utils.UniqueUtil;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.Report;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.ReportTemp;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.som.ReportTempMapper;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * 月报表实例化
 * Created by yangcs on 2017/4/4.
 */
public class ReportMonthService implements Job {
    public Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private ReportTempMapper reportTempMapper;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<ReportTemp> list = reportTempMapper.getMonthTemps();
        List<Report> reports = new ArrayList<>();
        Report report;
        if( list != null && list.size() > 0 ){
            for ( ReportTemp reportTemp:list ){
                report = new Report();
                report.setOrgId(reportTemp.getOrgId());
                // 每月1号凌晨2点执行
                report.setReportId(UniqueUtil.uuid());
                report.setReportTempId(reportTemp.getReportTempId());
                reports.add(report);
            }
        }
        if( reports.size() > 0 ){
            reportTempMapper.insertReport(reports);
        }
    }
}
